<?php

use Biz\model\ShopCategoryClassify;
use Biz\service\brand\BrandRecommendedTodayService;
use Biz\service\BrandPreFecture;
use Doraemon\service\position\Api;

class BrandRecommendedHeadAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_NOTHING;
    const MY_FOCUS = -2;//我的关注
    const POPULAR_BRANDS = -1;//热门品牌
    const RECOMMEND_PAGESIZE = 12;//算法-每日推荐品牌数量

    private array $data = [];

    public function main()
    {
        $this->getBannerList();
        $this->getCategoryList();
        $this->getBrandList();
        $this->data = $this->data ?? (object)[];
        $this->setSuccess($this->data);
    }

    /**
     * 获取banner
     */
    private function getBannerList()
    {
        $this->data['banner'] = Api::tab4FindBrandBanner($this->uid) ?? [];
    }

    /**
     * 获取品牌tab分类
     */
    private function getCategoryList()
    {
        $category = ShopCategoryClassify::getFirstDeepClassify();

        $this->data['category'] = array_merge([
            [
                'id' => self::MY_FOCUS,
                'title' => '我的关注',
            ],
            [
                'id' => self::POPULAR_BRANDS,
                'title' => '热门品牌',
            ],
        ], $category);
    }

    /**
     * 获取今日推荐品牌
     */
    private function getBrandList()
    {
        //获取后台配置的今日推荐品牌id
        $brandIds = BrandRecommendedTodayService::getBrandRecommendedTodayBrandIdArr();

        $this->data['brand_list'] = BrandPreFecture::recommendBrandsForChannelHead('发现品牌-今日推荐品牌', $this->uid, 0, 0,
                self::RECOMMEND_PAGESIZE, $brandIds, BrandPreFecture::RECOMMEND_TYPE_DAY) ?? [];

    }

}